package com.irdstudio.efp.riskm.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.riskm.service.dao.RscWarnGnlHistRuleInfoDao;
import com.irdstudio.efp.riskm.service.domain.RscWarnGnlHistRuleInfo;
import com.irdstudio.efp.riskm.service.facade.RscWarnGnlHistRuleInfoService;
import com.irdstudio.efp.riskm.service.vo.RscWarnGnlHistRuleInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 需求编号：【2019D0509】（业务提的需求编号）
 * 问题编号：【】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：【wanglh4】
 * 创建日期：【2019/11/20 20:52】
 * 功能描述：
 */
@Service("rscWarnGnlHistRuleInfoService")
public class RscWarnGnlHistRuleInfoServiceImpl implements RscWarnGnlHistRuleInfoService, FrameworkService {
    private static Logger logger = LoggerFactory.getLogger(RscWarnGnlHistRuleInfoServiceImpl.class);

    @Autowired
    private RscWarnGnlHistRuleInfoDao rscWarnGnlHistRuleInfoDao;

    @Override
    public List<RscWarnGnlHistRuleInfoVO> queryByRuleCode(RscWarnGnlHistRuleInfoVO rscWarnGnlHistRuleInfoVO) {
        logger.info("查询开始！");
        List<RscWarnGnlHistRuleInfoVO> list = new ArrayList<>();
        try {
            List<RscWarnGnlHistRuleInfo> rscWarnGnlHistRuleInfos = rscWarnGnlHistRuleInfoDao.queryByRuleCode(rscWarnGnlHistRuleInfoVO);
            list = (List<RscWarnGnlHistRuleInfoVO>) beansCopy(rscWarnGnlHistRuleInfos,RscWarnGnlHistRuleInfoVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }
        return list;
    }

    @Override
    public int updateByRuleCode(List<RscWarnGnlHistRuleInfoVO> ruleInfos) {
        logger.info("查询开始！查询条件：" + ruleInfos.toString());
        int num = 0;
        try {
            List<RscWarnGnlHistRuleInfo> rscWarnGnlHistRuleInfo = (List<RscWarnGnlHistRuleInfo>) beansCopy(ruleInfos,RscWarnGnlHistRuleInfo.class);
            num = rscWarnGnlHistRuleInfoDao.updateByRuleCode(rscWarnGnlHistRuleInfo);
        } catch (Exception e){
            num = -1;
            logger.error("数据转换出现异常!", e);
        }
        return num;
    }

    @Override
    public List<RscWarnGnlHistRuleInfoVO> queryRiskRuleHistAndCurrVal(RscWarnGnlHistRuleInfoVO rscWarnGnlHistRuleInfoVO) {
        logger.info("查询开始！查询条件：" + rscWarnGnlHistRuleInfoVO.toString());
        List<RscWarnGnlHistRuleInfoVO> list = null;
        try {
            RscWarnGnlHistRuleInfo queryRscWarnGnlHistRuleInfo = new RscWarnGnlHistRuleInfo();
            beanCopy(rscWarnGnlHistRuleInfoVO,queryRscWarnGnlHistRuleInfo);
            List<RscWarnGnlHistRuleInfo> rs = rscWarnGnlHistRuleInfoDao.queryRiskRuleHistAndCurrValByPage(rscWarnGnlHistRuleInfoVO);
            pageSet(rs,rscWarnGnlHistRuleInfoVO);
            list = (List<RscWarnGnlHistRuleInfoVO>) beansCopy(rs,RscWarnGnlHistRuleInfoVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }
        return list;
    }

    @Override
    public int updateRuleValue() {
        int num = 0;
        try {
            num = rscWarnGnlHistRuleInfoDao.updateRuleValue();
        } catch (Exception e) {
            num = -1;
            logger.error("数据转换出现异常!", e);
        }
        return num;
    }
}
